<?php defined('_JEXEC') or die('Restricted access'); ?>

<?php JHTML::_('behavior.tooltip'); ?>

<?php
	// Set toolbar items for the page
	$edit		= JRequest::getVar('edit',true);
	$text = !$edit ? JText::_( 'New' ) : JText::_( 'Edit' );
	JToolBarHelper::title(   JText::_( 'MWC Image' ).': <small><small>[ ' . $text.' ]</small></small>' );
	JToolBarHelper::save();
	if (!$edit)  {
		JToolBarHelper::cancel();
	} else {
		// for existing items the button is renamed `close`
		JToolBarHelper::cancel( 'cancel', 'Close' );
	}
	JToolBarHelper::help( 'screen.pdf.edit' );
?>

<script language="javascript" type="text/javascript">
	function submitbutton(pressbutton) {
		var form = document.adminForm;
		if (pressbutton == 'cancel') {
			submitform( pressbutton );
			return;
		}
		//submitform( pressbutton );
		// do field validation
//		if ((form.thumbnail.value == "") || (!checkExt('image')))
		if ((form.thumbnail.value == ""){
		{
			alert( "<?php echo JText::_( 'You must choose an image with extension: gif, jpeg, jpg, png.', true ); ?>" );
		}
		else {
			submitform( pressbutton );
		}
	}
</script>
<style type="text/css">
	table.paramlist td.paramlist_key {
		width: 92px;
		text-align: left;
		height: 30px;
	}
</style>

<form action="index.php" method="post" name="adminForm" id="adminForm">
<div align="center" style="width:70%" class="col">
	<fieldset class="adminform">
		<legend><?php echo JText::_( 'Details' ); ?></legend>

		<table class="admintable">
		<tr>
			<td width="100" align="right" class="key">
				<label for="title">
					<?php echo JText::_( 'Title' ); ?>:
				</label>
			</td>
			<td>
				<input class="text_area" type="text" name="title" id="title" size="50" maxlength="250" value="<?php echo $this->pdf->title;?>" />
			</td>
		</tr>
		<tr>
			<td width="100" align="right" class="key">
				<label for="alias">
					<?php echo JText::_( 'Thumbnail' ); ?>:
				</label>
			</td>
			<td><a href="<?php echo $this->pdf->thumbnail;?>" class="modal-button"><img id='thumbnail_src' width="150" height="120" name='thumbnail_src' src="<?php echo $this->pdf->thumbnail;?>"  /></a>
				<input readonly="readonly"  class="text_area" type="text" name="thumbnail" id="thumbnail" size="50" maxlength="250" value="<?php echo $this->pdf->thumbnail;?>" onchange="javascript:
						if (document.forms.adminForm.thumbnail.value!='') {
							document.forms.adminForm.thumbnail.value = document.thumbnail_src.src='../'+document.forms.adminForm.thumbnail.value;
						} 
						else {
							document.forms.adminForm.thumbnail.value = document.thumbnail_src.src='../includes/js/ThemeOffice/component.png';
						}"/><a class="modal-button" rel="{handler: 'iframe', size: {x: 570, y: 400}}" href="index.php?option=com_rokquickcart&amp;view=images&amp;tmpl=component&amp;e_name=thumbnail">Upload Image</a>
			</td>
		</tr>
<!-- 		
        <tr>
			<td width="100" align="right" class="key">
				<label for="alias">
					<?php echo JText::_( 'PDF File' ); ?>:
				</label>
			</td>
			<td>
				<input readonly="readonly" class="text_area" type="text" name="media_file" id="media_file" size="50" maxlength="250" value="<?php echo $this->pdf->media_file; ?>" /><a class="modal-button" rel="{handler: 'iframe', size: {x: 570, y: 400}}" href="index.php?option=com_rokquickcart&amp;view=images&amp;tmpl=component&amp;e_name=media_file">Upload PDF File</a>
			</td>
		</tr>
-->		
		<tr>
			<td valign="top" align="right" class="key">
				<label for="alias">
					<?php echo JText::_( 'Description' ); ?>:
				</label>
			</td>
			<td>
				<textarea class="text_area" cols="40" rows="6" name="content" id="content"><?php echo $this->pdf->content; ?></textarea>
			</td>
		</tr>
		<tr>
			<td valign="top" align="right" class="key">
				<?php echo JText::_( 'Published' ); ?>:
			</td>
			<td>
				<?php echo $this->lists['published']; ?>
			</td>
		</tr>
		
		<tr>
			<td valign="top" align="right" class="key">
				<label for="ordering">
					<?php echo JText::_( 'Ordering' ); ?>:
				</label>
			</td>
			<td>
				<?php echo $this->lists['ordering']; ?>
			</td>
		</tr>
	</table>
	</fieldset>
</div>
<!--<div class="col width-50">
	<fieldset class="adminform">
		<legend><?php //echo JText::_( 'Parameters' ); ?></legend>

		<table class="admintable">
		<tr>
			<td colspan="2">
				<?php //echo $this->params->render();?>
			</td>
		</tr>
		</table>
	</fieldset>
</div>

<div class="col width-50">
	<fieldset class="adminform">
		<legend><?php //echo JText::_( 'Description' ); ?></legend>

		<table class="admintable">
		<tr>
			<td>
				<textarea class="text_area" cols="44" rows="9" name="content" id="content"><?php //echo $this->pdf->content; ?></textarea>
			</td>
		</tr>
		</table>
	</fieldset>
</div>
--><div class="clr"></div>

	<input type="hidden" name="option" value="com_mwc_images" />
	<input type="hidden" name="cid[]" value="<?php echo $this->pdf->id; ?>" />
	<input type="hidden" name="task" value="" />
	<?php echo JHTML::_( 'form.token' ); ?>
</form>
<script type="text/javascript">
function checkExt(filetype)
{
	if (filetype=='image')
	{
		validext=["gif","jpg","jpeg","png"];
		filename = document.getElementById('thumbnail').value;
	}
	else
	{
		validext=["pdf"];
		filename = document.getElementById('media_file').value;
	}
	
	var filelength = parseInt(filename.length) - 3;
	var fileext = filename.substring(filelength,filelength + 3);
	temp=0;
	for (var i = 0; i < validext.length; i++) 
	{
		if (fileext.toLowerCase()==validext[i])
		{
			temp=1;
		}
	}
	if (temp ==0)
	{
		return 0;
	}
	else
	{
		return 1;
	}
}
</script>